package com.zg.scf.web;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zg.common.core.R;
import com.zg.scf.domain.req.*;
import com.zg.scf.domain.vo.ScfRoleVo;
import com.zg.scf.service.ScfRoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@Api(tags = {"角色管理"})
@RestController
@RequiredArgsConstructor
public class ScfRoleController {

    private final ScfRoleService scfRoleService;

    @ApiOperation("新增角色")
    @PostMapping("/role/add")
    public R<Void> systemAdd(@RequestBody @Valid ScfRoleAddReq req) {
        scfRoleService.add(req);
        return R.success();
    }

    @ApiOperation("修改角色")
    @PostMapping("/role/edit")
    public R<Void> edit(@RequestBody @Valid ScfRoleEditReq req) {
        scfRoleService.edit(req);
        return R.success();
    }

    @ApiOperation("删除角色")
    @PostMapping("/role/remove")
    public R<Void> remove(@RequestBody List<Long> idList) {
        scfRoleService.remove(idList);
        return R.success();
    }

    @ApiOperation("分页查询系统角色")
    @PostMapping("/role/system/page")
    public R<IPage<ScfRoleVo>> pageSystem(@RequestBody @Valid ScfRolePageReq req) {
        IPage<ScfRoleVo> page = scfRoleService.pageSystem(req);
        return R.success(page);
    }

    @ApiOperation("分页查询用户角色")
    @PostMapping("/role/company/page")
    public R<IPage<ScfRoleVo>> pageCompany(@RequestBody @Valid ScfRolePageReq req) {
        IPage<ScfRoleVo> page = scfRoleService.pageCompany(req);
        return R.success(page);
    }

    @ApiOperation("查询角色")
    @PostMapping("/role/list")
    public R<List<ScfRoleVo>> list(@RequestBody @Valid ScfRoleListReq req) {
        List<ScfRoleVo> list = scfRoleService.list(req);
        return R.success(list);
    }
}
